package thread;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Ap0stoL2
 * Date: 2023-07-25
 * Time: 13:46
 */

class Aproblem{

    List<Integer> ls = new ArrayList<>();

    public int count=0;

    public void func1(){
        synchronized(this){
            System.out.println("方法1");
            for(int i=0;i<5000;i++) count++;
        }
    }

    public void func2(){
        synchronized(ls){
            System.out.println("方法2");
            for(int i=0;i<5000;i++) count++;

        }
    }
}
public class problem1 {
    public static void main(String[] args) throws InterruptedException {
        Aproblem a = new Aproblem();

        Thread t1 = new Thread(()->{
            a.func1();
        });

        Thread t2 = new Thread(()->{
            a.func2();
        });

        t1.start();
        t2.start();

        t1.join();
        t2.join();

        System.out.println(a.count);
    }
}
